package com.cg.design.graphicdesignpattern.interpreter.language;

/**
 * 对应<command>标签的类，继承了BaseNode类
 *
 * @program: LeetCode->CommandNode
 * @author: cg
 * @create: 2022-04-06 08:48
 **/
public class CommandNode extends BaseNode {

    /**
     * 保存的是与<repeat command>对应的RepeatCommandNode类的实例
     */
    private BaseNode node;

    @Override
    public void parse(Context context) throws ParseException {
        if ("repeat".equals(context.currentToken())) {
            node = new RepeatCommandNode();
            node.parse(context);
        } else {
            node = new PrimitiveCommandNode();
            node.parse(context);
        }
    }

    @Override
    public void execute() throws ExecuteException {
        node.execute();
    }

    @Override
    public String toString() {
        return node.toString();
    }
}
